﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Xsl;
using Ent.Inscripcion.Core;
using Ent.Inscripcion.Core.Core;
using Ext.Net;

namespace Ent.Inscripcion.Presentacion.Administracion.Reportes
{
    public partial class ReporteTutorias : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            stoVariables.DataSource = CatalogoItemLista.GetListaCatalogos("REPEXAMEN");
            stoVariables.DataBind();
        }

        protected void btnVerReporte_Click(object sender, EventArgs e)
        {
            try
            {

                var variable = Session["Variable"].ToString();
                var nombreVariable = Session["Nombre"].ToString();
                var criteria = DatoEstadisticaCriterio.NewDatoEstadisticaCriterio();
                criteria.Variable = variable;
                criteria.TipoReporte = Tipo.Tutoria;
                var datos = DatosEstadisticaLista.GetDatosEstadisticaLista(criteria);
                Chart1.DataSource = datos;
                Chart1.Titles[0].Text = string.Format("{0} por {1}", Chart1.Titles[0].Text, nombreVariable);
                this.Chart1.Series["Series 1"].ToolTip = "#AXISLABEL #VAL{0}";
                Chart1.Series["Series 1"].XValueMember = "Valor";
                Chart1.Series["Series 1"].YValueMembers = "Cantidad";
                Chart1.DataBind();
                var criteriaValores = ValorEstadisticaCriterio.NewValorEstadisticaCriterio();
                criteriaValores.Variable = variable;
                criteriaValores.TipoReporte = Tipo.Tutoria;
                stoDatosReporteEstadistica.DataSource =
                    ValoresEstadisticaLista.GetValoresEstadisticaLista(criteriaValores);
                stoDatosReporteEstadistica.DataBind();
            }
            catch (Exception ex)
            {
                Util.RegistarLog(ex);
            }
        }


        protected void cbxVariable_Select(object sender, DirectEventArgs e)
        {
            try
            {
                var n = e.ExtraParams["Nombre"];
                var v = e.ExtraParams["Variable"];
                Session["Nombre"] = n;
                Session["Variable"] = v;
            }
            catch (Exception ex)
            {
                e.Success = false;
                Util.RegistarLog(ex);
            }
        }
        protected void ToExcel(object sender, EventArgs e)
        {
            string json = GridData.Value.ToString();
            var eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;

            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=reporteRegistradosTutorias.xls");
            var xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();
        }
    }
}